package com.scut.edu.wanyou.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.scut.edu.wanyou.channel.Category;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Parser {
	
	public static Bundle jsonToBundle(String json) throws JSONException
	{
		JSONObject jsonObject = new JSONObject(json);
		Iterator iterator = jsonObject.keys();
		Bundle bundle = new Bundle();
		while(iterator.hasNext())
		{
			String key = (String)iterator.next();
			bundle.putString(key, jsonObject.getString(key));
		}
		return bundle;
	}
	
	public static List<Category> getCatsFromJson(String json) throws JSONException
	{
		List<Category> cats = new ArrayList<Category>();
		JSONArray array = new JSONArray(json);
		for(int i=0;i<array.length();++i){
			Category cat = new Category();
			cat.parser(array.getJSONObject(i));
			cats.add(cat);
		}
		return cats;
		
	}
	
}
